declare var wx: any;
declare var tt: any;
import { EnumplatFrom } from "./EnumplatFrom";
import Instance from "../Utils/Instance";
import SdkMgr from "./SdkMgr";
import { sys } from "cc";
import { LocalUtil } from "../Utils/LocalUtil";
import ProtoBufManager from "../../Game/proto/ProtoBufManager";

export default class SdkTool {
    public sdk: SdkMgr = null;
    public uid: number = 111;
    /**玩家openid */
    public openid: string = `123123`;
    /**是否第一次进入游戏 */
    public isFirst: boolean = false;
    /**场景值 */
    public sceneAppId: number = 1;
    /**是否支持侧边栏 */
    public sidebar: boolean = false;
    /**侧边栏进入 */
    public isSidebar: boolean = false;
    /**顶部偏移 */
    public topmenu: number = 0;
    /**启动参数 */
    public query: Object = {};
    /**昵称 */
    public nickName: string = ``;
    /**头像 */
    public avatarUrl: string = ``;
    public static get ins(): SdkTool {
        return Instance.get(SdkTool);
    }
    public initSdk(): void {
        switch (this.platform) {
            case EnumplatFrom.TT:
                this.sdk = new SdkMgr(EnumplatFrom.TT);
                break;
            case EnumplatFrom.WX:
                this.sdk = new SdkMgr(EnumplatFrom.WX);
                break;
            case EnumplatFrom.PC:
                this.sdk = new SdkMgr(EnumplatFrom.PC);
                break;
        }
        this.sdk.init(null, null);
    }
    /**平台参数 */
    public get platform(): string {
        if (this.isInTt) {
            return EnumplatFrom.TT;
        }
        if (this.isInWeChat) {
            return EnumplatFrom.WX;
        }
        return EnumplatFrom.PC;
    }
    public get channelId(): number {
        switch (this.platform) {
            case EnumplatFrom.TT:
                return ProtoBufManager.ins.common.EChannelId.DY;
            case EnumplatFrom.WX:
                return ProtoBufManager.ins.common.EChannelId.WX;
            case EnumplatFrom.PC:
                return ProtoBufManager.ins.common.EChannelId.Visitor;
        }
    }
    /**是否在微信小程序中 */
    public get isInWeChat() {
        return typeof wx !== 'undefined' && typeof tt == 'undefined';
    }
    /**是否在抖音小程序中 */
    public get isInTt() {
        return typeof tt !== 'undefined';
    }
    public getMenuButtonBoundingClientRect(): void {
        this.sdk.getMenuButtonBoundingClientRect();
    }
    /**
     * 设置即时通讯排名数据
     * @param val 排名数据
     */
    public setImRankData(val: number): void {
        this.sdk.setImRankData(val);
    }
    /**
     * 获取排行榜列表,抖音下自动渲染排行榜列表
     */
    public getImRankList(): void {
        this.sdk.getImRankList();
    }
    /**
     * 震动
     */
    public get isShock(): number {
        var isShock = LocalUtil.ins.getCookie(`linkisShock`);
        if (isShock) {
            return Number(isShock);
        }
        return 1;
    }
    public set isShock(val: number) {
        LocalUtil.ins.setCookie(`linkisShock`, val);
    }
    /**
     * 震动
     */
    public playShock(): void {
        if (this.isShock != 1) {
            return;
        }
        this.sdk.vibrateShort();
    }
    /**
   * 设置剪贴板数据
   *
   * @param val 需要设置到剪贴板的数据
   */
    public setClipboardData(val: string): void {
        this.sdk.setClipboardData(val);
    }
}